﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;

namespace QLPMT_DAO
{
    public class DataProvider
    {
        public string ConnectString = ""; //="Data Source=NGUYENNAM-PC\\SQLEXPRESS;Initial Catalog=QL_PhongMachTu;User ID=sa;Password=123";
        public static string host;
        public static string db_name;
        public static string db_user;
        public static string db_pass;
        SqlConnection cn;
        public DataProvider()
        {
            //ConnectString = "Data Source=" + host + ";Initial Catalog=" + db_name + ";User ID=" + db_user + ";Password=" + db_pass;
            ConnectString = "Data Source=" + host + ";Initial Catalog=" + db_name + ";User ID=" + db_user + ";Password=" + db_pass;
            //string t = "Data Source=" + host + ";Initial Catalog=" + db_name + ";User ID=" + db_user + ";Password=" + db_pass;
            cn = new SqlConnection(ConnectString);
        }
        public DataProvider(string _host, string _db_name, string _db_user, string _db_pass)
        {
            //ConnectString = "Data Source=" + host + ";Initial Catalog=" + db_name + ";User ID=" + db_user + ";Password=" + db_pass;
            ConnectString = "Data Source=" + _host + ";Initial Catalog=" + _db_name + ";User ID=" + _db_user + ";Password=" + _db_pass;
            cn = new SqlConnection(ConnectString);
        }
        public void Connect()
        {
            try
            {
                cn.Open();
            }
            catch
            {


            }

        }
        public void Disconnect()
        {
            cn.Close();
        }
        public SqlDataReader ExecuteReader(string sql)
        {
            SqlCommand command = new SqlCommand(sql, cn);
            return command.ExecuteReader();
        }
        public void ExecuteQuery(string sql)
        {
            SqlCommand cmd = new SqlCommand(sql, cn);
            cmd.ExecuteNonQuery();
        }
    }
}
